/*
 * @(#)WindowTableModel.java
 */
package com.pluginsacceptor.acceptor.ui.info;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;

import javax.swing.JButton;

import org.apache.log4j.Logger;

import com.pluginsacceptor.acceptor.activator.PluginList;


/**
 * Custom table model
 */
public class WindowTableModel extends javax.swing.table.AbstractTableModel {

    /** Logger */
    private static final Logger LOG = Logger.getLogger(PluginInfoRenderer.class);


    /** */
    private static final long serialVersionUID = 1L;

    /** */
    private static final String[] COLUMN_NAMES = new String[] {"Plugin name", "Linked plugins", ""};

    /** */
    private static final Class<?>[] COLUMN_TYPES = new Class<?>[] {String.class, String.class, JButton.class};

    @Override public int getColumnCount() {
        return COLUMN_NAMES.length;
    }

    @Override public int getRowCount() {
        return PluginList.getActivePlugins().size();
    }

    @Override public String getColumnName(final int columnIndex) {
        return COLUMN_NAMES[columnIndex];
    }

    @Override public Class<?> getColumnClass(final int columnIndex) {
        return COLUMN_TYPES[columnIndex];
    }

    @Override public Object getValueAt(final int rowIndex, final int columnIndex) {
        switch (columnIndex) {
            case 0: return PluginList.getActivePlugins().get(rowIndex).getName();
            case 1: return Arrays.asList(PluginList.getActivePlugins().get(rowIndex).getRequirements());
            case 2: final JButton button = new JButton("Del");
                    button.addActionListener( new ActionListener() {
                        @Override
                        public void actionPerformed(final ActionEvent arg0) {
                            button.setEnabled(false);
                        }
                      }
                   );
                   return button;
            default: return "Error";
        }
    }
}
